package com.dkd.interfaceinfo.controller;


import com.dkd.common.core.domain.AjaxResult;
import com.dkd.interfaceinfo.domain.InterfaceInfo;
import com.dkd.interfaceinfo.domain.VO.UserInterfaceInfoVo;
import com.dkd.interfaceinfo.mapper.InterfaceInfoMapper;
import com.dkd.interfaceinfo.mapper.UserInterfaceInfoMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("analysis")
public class AnalysisController {

    @Autowired
    private UserInterfaceInfoMapper userInterfaceInfoMapper;
    @Autowired
    private InterfaceInfoMapper interfaceInfoMapper;

    @GetMapping("topInterfaceInvoke/{limit}")
    public AjaxResult ListTopInterfaceInvoke(@PathVariable("limit")  int limit){
        List<UserInterfaceInfoVo> userInterfaceInfoVos = userInterfaceInfoMapper.countInterfaceInvokeCount(limit);
        userInterfaceInfoVos.forEach(userInterfaceInfoVo -> {
            InterfaceInfo interfaceInfo = interfaceInfoMapper.selectInterfaceInfoById(userInterfaceInfoVo.getId());
            BeanUtils.copyProperties(interfaceInfo,userInterfaceInfoVo);
        });
        return AjaxResult.success(userInterfaceInfoVos);
    }
}
